<?php $this->pageTitle = 'Update Parameters'; ?>
<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'config-form',
        'enableAjaxValidation' => false,
            ));
    ?>

    <div class="row buttons" align="right">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php if ($model->type == 'text') : ?>
        <?php echo $form->errorSummary($model); ?>
        <div class="row">
            <?php echo $form->hiddenField($model, 'type'); ?>
            <?php echo $form->hiddenField($model, 'name', array('readonly' => true)); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'value'); ?>
            <?php
            $this->widget('application.extensions.gui.tinymce.ETinyMce', array(
                'name' => 'Config[value]',
                'value' => $model->value,
                'editorTemplate' => 'full'
            ));
            ?>
            <?php echo $form->error($model, 'value'); ?>
        </div>
    <?php else : ?>
        <?php if ($model->isNewRecord): ?>
            <div class="row">
                <?php echo $form->hiddenField($model, 'type'); ?>
                <?php echo $form->hiddenField($model, 'name'); ?>
            </div>
            <table id="tblkey" style="min-width: 520px">
                <tr>
                    <td>Key: <input type="text" name="Keys[]" value="" style="width: 100%" /></td>
                    <td>Value: <input type="text" name="Values[]" value="" style="width: 100%" /></td>
                </tr>
            </table>
            <div class="row" align="right" style="width: 480px">
                <?php
                echo CHtml::button('Add Key', array(
                    'class' => 'controls',
                    'onclick' => '$("#tblkey").append(\'<tr><td>Key: <input type="text" name="Keys[]" value="" style="width: 100%" /></td><td>Value: <input type="text" name="Values[]" value="" style="width: 100%" /></td></tr>\');',
                ));
                ?>
            </div>
        <?php else: ?>
            <!--            <div class="row">
                            
                        </div>-->
            <?php
            if ($model instanceof Config) :
                echo $form->hiddenField($model, 'type');
                echo $form->hiddenField($model, 'name');
                ?>
            <table id="tblkey" style="min-width: 520px">
                    <?php
                    $data = unserialize($model->value);
                    foreach ($data as $key => $value) {
                        echo '<tr>';
                        echo "<td>Key <input type='text' name=\"Keys[]\" value=\"{$key}\" style=\"width: 100%\" /></td>";
                        echo "<td>Value <input type='text' name=\"Values[]\" value=\"{$value}\" style=\"width: 100%\" /></td>";
                        echo '</tr>';
                    }
                    ?>
                </table>
                <div class="row" align="right" style="width: 480px">
                    <?php
                    echo CHtml::button('Add Key', array(
                        'class' => 'controls',
                        'onclick' => '$("#tblkey").append(\'<tr><td>Key: <input type="text" name="Keys[]" value="" style="width: 100%" /></td><td>Value: <input type="text" name="Values[]" value="" style="width: 100%" /></td></tr>\');',
                    ));
                    ?>
                </div>
                <?php
            else :
                echo $form->hiddenField($model[0], 'type');
                echo $form->hiddenField($model[0], 'name');
                foreach ($model as $node) {
                    echo CHtml::tag('div', array('class' => 'bold'), CHtml::link(ucwords($node->name), array('update', 'name' => $node->name)));
                    $data = unserialize($node->value);
                    foreach ($data as $key => $value) {
                        echo '<div class="row" style="padding-left: 20px">';
                        echo "<label>" . ucwords($key) . "</label>";
                        echo CHtml::textField("{$node->name}[{$key}]", $value);
                        echo '</div>';
                    }
                }
            endif;
            ?>
        <?php endif; ?>
    <?php endif; ?>

    <div class="row buttons" align="right">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->